//
//  BClogInView.m
//  BangcaiBuy
//
//  Created by lsy on 16/6/14.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BClogInView.h"

@implementation BClogInView
- (instancetype)initWithFrame:(CGRect)frame backImage:(UIImage *)ima
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView:ima];
    }
    return self;
}

- (void)createView:(UIImage*)ima
{
    self.backgroundColor = [UIColor whiteColor];

    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 270 * hx)];
    headView.backgroundColor = BangcaiOrange;
    UIImageView *imageView = [[UIImageView alloc] init];
    [headView addSubview:imageView];
    UILabel *phoneLab = [[UILabel alloc] init];
    UILabel *pssLab = [[UILabel alloc] init];
    self.logIn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.findPass = [UIButton buttonWithType:UIButtonTypeSystem];
    self.regist = [UIButton buttonWithType:UIButtonTypeSystem];
    
    imageView.image = ima;
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.bottom.mas_equalTo(-30);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(105);
        
        
    }];
    UILabel *phoneLine = [[UILabel alloc] init];
    UILabel *pssLine = [[UILabel alloc] init];
    
    phoneLine.backgroundColor = [UIColor colorWithRed:0.878  green:0.878  blue:0.878 alpha:1];
    pssLine.backgroundColor = [UIColor colorWithRed:0.878  green:0.878  blue:0.878 alpha:1];
    
    phoneLab.userInteractionEnabled = YES;
    phoneLab.layer.borderColor = [[UIColor colorWithRed:204/255.0  green:204/255.0  blue:204/255.0 alpha:1] CGColor];
    phoneLab.backgroundColor = [UIColor clearColor];
    UIImageView *userImg = [[UIImageView alloc] init];
    userImg.image = [UIImage imageNamed:@"手机"];
    [phoneLab addSubview:userImg];
    self.phoneNum = [[UITextField alloc] init];
    self.phoneNum.placeholder = @"用户";
    [self.phoneNum setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.phoneNum setValue:[UIFont systemFontOfSize:20] forKeyPath:@"_placeholderLabel.font"];
    [phoneLab addSubview:self.phoneNum];
    
    

    pssLab.userInteractionEnabled = YES;
    pssLab.layer.borderColor = [[UIColor colorWithRed:204/255.0  green:204/255.0  blue:204/255.0 alpha:1] CGColor];
    pssLab.backgroundColor = [UIColor clearColor];
    UIImageView *pssImg = [[UIImageView alloc] init];
    pssImg.image = [UIImage imageNamed:@"密码"];
    [pssLab addSubview:pssImg];
    self.passWord = [[UITextField alloc] init];
    self.passWord.placeholder = @"密码";
    self.passWord.secureTextEntry = YES;
    [self.passWord setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.passWord setValue:[UIFont systemFontOfSize:20] forKeyPath:@"_placeholderLabel.font"];
    [pssLab addSubview:self.passWord];
    self.logIn.layer.cornerRadius = 3;
    self.logIn.backgroundColor = BangcaiOrange;
    [self.logIn setTitle:@"登录" forState:UIControlStateNormal];
    
    [self.logIn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.logIn.titleLabel.font = [UIFont systemFontOfSize:20];
    
    [self.findPass setTitle:@"忘记密码?" forState:UIControlStateNormal];
    [self.findPass setTitleColor:BangcaiOrange forState:UIControlStateNormal];
    self.findPass.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.regist setTitle:@"注册" forState:UIControlStateNormal];
    [self.regist setTitleColor:BangcaiOrange forState:UIControlStateNormal];
    self.regist.titleLabel.font = [UIFont systemFontOfSize:18];
    
    [self addSubview:headView];
    [self addSubview:phoneLab];
    [self addSubview:pssLab];
    [self addSubview:self.logIn];
    [self addSubview:self.findPass];
    [self addSubview:self.regist];
    [self addSubview:phoneLine];
    [self addSubview:pssLine];
    
    [phoneLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.height.mas_equalTo(50 * hx);
        make.width.mas_equalTo(SCREEN_WIDTH);
        make.top.mas_equalTo(310 * hx);
    }];

    [phoneLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1);
        make.width.mas_equalTo(SCREEN_WIDTH - 24);
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(phoneLab.mas_bottom);
        
    }];
    [userImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.and.height.mas_equalTo(25 * hx);
        make.top.and.left.mas_equalTo(12 * wx);
    }];
    [self.phoneNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(phoneLab);
        make.top.and.right.bottom.mas_equalTo(0);
        make.left.mas_equalTo(50);
        
    }];
    
    [pssLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.and.height.equalTo(phoneLab);
        make.top.mas_equalTo(390 * hx);
        
    }];
    [pssLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1);
        make.width.mas_equalTo(SCREEN_WIDTH - 24);
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(pssLab.mas_bottom);
    }];
    [pssImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.and.height.mas_equalTo(25 * hx);
        make.top.and.left.mas_equalTo(12 * wx);

    }];
    
    [self.passWord mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.equalTo(phoneLab);
        make.top.and.right.bottom.mas_equalTo(0);
        make.left.mas_equalTo(50);
        
    }];
    [self.logIn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.height.equalTo(phoneLab);
        make.width.mas_equalTo(SCREEN_WIDTH - 20);
        make.top.mas_equalTo(550 * hx);
    }];
    
    [self.findPass mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(20);
        make.top.mas_equalTo(pssLine.mas_bottom).with.offset(20);
    }];
    
    [self.regist mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(20);
        make.top.equalTo(self.findPass);
        make.right.mas_equalTo(-30);
    }];
    
    
    

}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.phoneNum resignFirstResponder];
    [self.passWord resignFirstResponder];
    return YES;
}



-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.phoneNum resignFirstResponder];
    [self.passWord resignFirstResponder];
}
@end
